/*
 * @Author: shengduiliang 1107722390@qq.com
 * @Date: 2024-05-04 12:54:35
 * @LastEditors: shengduiliang 1107722390@qq.com
 * @LastEditTime: 2024-05-05 19:46:05
 * @FilePath: /treasure/src/store/userSlice.ts
 * @Description: 用户数据
 */
import { Gender, UserRole } from "@/types";
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { UserTreasury } from "./treasurySlice";

export interface Role {
  // id: string;
  name: UserRole;
}

export interface User {
  // id: string;
  username?: string;
  avatar?: string;
  openId: string;
  gender?: Gender;
  enabled: boolean;
  roles: Role[];
  createTime: string;
  updateTime?: string;
  treasuryList: UserTreasury[];
}



const userSlice = createSlice({
  name: 'user',
  initialState: null as User | null,
  reducers: {
    setUser: (state, action: PayloadAction<User>) => {
      return { ...state, ...action.payload }
    },
    clearUser: () => null
  }
})

export const { setUser, clearUser } = userSlice.actions

export default userSlice.reducer